var utils = require("../../utils/util.js")

Page({
  data: {
    year:new Date().getFullYear(),
    month: new Date().getMonth()+1,
    day: new Date().getDate(),
    hotMusic:{},
    newMusic:{},
    rockMusic:{},
    musics:[],
    category:""
  },
  /**
   * http协议：
   *  http
   *  https:更加安全
   * 
   * wx.require
   *  1.必须是https
   *  2.必须添加合法域名
   * 
   */
  
  onLoad: function () {
    utils.http("https://wwtliu.com/sxtstu/music/baidu/list.php?type=1&count=3&offset=0", this.getMusicInfo,"newMusic","新歌榜")
    utils.http("https://wwtliu.com/sxtstu/music/baidu/list.php?type=2&count=3&offset=0", this.getMusicInfo,"hotMusic","热歌榜")
    utils.http("https://wwtliu.com/sxtstu/music/baidu/list.php?type=11&count=3&offset=0", this.getMusicInfo,"rockMusic","摇滚榜")
    wx.showLoading({
      title: '你是丑八怪',
    })
  },

  getMusicInfo: function (data, type, category){
    wx.hideLoading();
    var readyMusic = {};
    readyMusic[type] = {
      musics: data.song_list,
      category:category
    }
    this.setData(readyMusic)
    console.log(this.data)
  },

  musicHandler:function(event){
    var type = event.currentTarget.dataset.type;
    wx.navigateTo({
      url: '../music/music?type=' + type,
    })
  }
})
